import table from '@/components/dt/table/render.js'
let _this = null

//设定操作项
function setHandel(_this, key) {
  console.log('zhk ~ file: setOrderColumns.js:6 ~ setHandel ~ _this:', _this)
  return {
    field: 'handles',
    title: '操作项',
    align: 'center',
    fixed: 'right',
    visible: !_this.isCheck,
    cell: (row) => {
      let btn = []
      btn.push({
        title: '无需设定',
        click: () => {
          _this.noSet(row, key)
        }
      })
      return { btn }
    }
  }
}

//设定表头
function setList(_this) {
  return {
    count: [
      {
        align: 'center',
        header: {
          requiredTxt: {
            title: `${_this.modalType == 'SUBSCRIPTION' ? '认购' : '签约'}套数目标(套)`
          }
        },
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'initUnit',
              data: row,
              type: 'number',
              disabled: _this.isCheck,
              placeholder: ' ',
              blur: () => {
                _this.targetChange(row, 'goalCount')
              }
            })
          }
        }
      },
      setHandel(_this, 'goalCount')
    ],
    money: [
      {
        align: 'center',
        header: {
          requiredTxt: {
            title: `${_this.modalType == 'SUBSCRIPTION' ? '认购' : '签约'}金额目标(万)`
          }
        },
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'initUnit',
              data: row,
              type: 'number',
              disabled: _this.isCheck,
              placeholder: ' ',
              blur: () => {
                _this.targetChange(row, 'goalMoney')
              }
            })
          }
        }
      },
      setHandel(_this, 'goalMoney')
    ],
    area: [
      {
        title: `${_this.modalType == 'SUBSCRIPTION' ? '认购' : '签约'}面积目标(㎡)`,
        align: 'center',
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'initUnit',
              data: row,
              type: 'number',
              disabled: _this.isCheck,
              placeholder: ' ',
              blur: () => {
                _this.targetChange(row, 'goalArea')
              }
            })
          }
        }
      },
      {
        field: 'handles',
        title: '操作项',
        align: 'center',
        fixed: 'right',
        visible: !_this.isCheck
      }
    ]
  }
}
function adjustHandel(_this, key) {
  return {
    field: 'handles',
    title: '操作项',
    align: 'center',
    fixed: 'right',
    cell: (info) => {
      let btn = []
      btn.push({
        title: `调整记录(${info.updateNum ? info.updateNum : 0})`,
        click: () => {
          _this.changeLog(info, key)
        }
      })
      return { btn }
    }
  }
}
//调整表头
function adjustList(_this) {
  return {
    count: [
      {
        field: 'initUnit',
        title: `初始套数目标(套)`,
        align: 'center'
      },
      {
        field: 'currentUnit',
        align: 'center',
        header: {
          requiredTxt: {
            title: `调整套数目标(套)`
          }
        },
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'currentUnit',
              type: 'number',
              disabled: _this.isCheck,
              placeholder: ' ',
              data: row,
              blur: () => {
                _this.adjustChange(row.currentUnit, row, 'goalCount')
              }
            })
          }
        }
      },
      {
        field: 'dValue',
        title: `调整差(套)`,
        align: 'center'
      },
      adjustHandel(_this, 'NUMBER')
    ],
    money: [
      {
        field: 'initUnit',
        title: `初始金额目标(万)`,
        align: 'center'
      },
      {
        field: 'currentUnit',
        align: 'center',
        header: {
          requiredTxt: {
            title: `调整金额目标(万)`
          }
        },
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'currentUnit',
              disabled: _this.isCheck,
              type: 'number',
              placeholder: ' ',
              data: row,
              blur: () => {
                _this.adjustChange(row.currentUnit, row, 'goalMoney')
              }
            })
          }
        }
      },
      {
        field: 'dValue',
        title: `调整差(万)`,
        align: 'center'
      },
      adjustHandel(_this, 'AMOUNT')
    ],
    area: [
      {
        field: 'initUnit',
        title: `初始面积目标(㎡)`,
        align: 'center',
        slots: {
          default: ({ row }, h) => {
            if (!_this.areaInitUnit) {
              return table.cell.input(_this, h, {
                key: 'initUnit',
                disabled: _this.isCheck,
                type: 'number',
                placeholder: ' ',
                data: row,
                blur: () => {
                  _this.areaChange(row.initUnit, row, 'initUnit')
                }
              })
            } else {
              return row.initUnit
            }
          }
        }
      },
      {
        title: `调整面积目标(㎡)`,
        field: 'currentUnit',
        align: 'center',
        slots: {
          default: ({ row }, h) => {
            if (_this.areaInitUnit) {
              return table.cell.input(_this, h, {
                key: 'currentUnit',
                disabled: _this.isCheck,
                type: 'number',
                placeholder: ' ',
                data: row,
                blur: () => {
                  _this.areaChange(row.currentUnit, row, 'currentUnit')
                }
              })
            } else {
              return row.currentUnit
            }
          }
        }
      },
      {
        field: 'dValue',
        title: `调整差(㎡)`,
        align: 'center'
      },
      adjustHandel(_this, 'AREA')
    ]
  }
}

function options(vm) {
  _this = vm
  if (_this.setGoalType == 'SET') {
    return setList(_this)
  } else {
    return adjustList(_this)
  }
}

export default {
  options
}
